package com.cmse.persistence.enmu;

import org.apache.commons.lang.StringUtils;

/**
 * @author wulibin, exceptsky@gmail.com, 2012-3-12 下午8:07:28
 * 
 */
public enum RoleType {
	USER(1, "user"),
	ADMIN(2, "admin"),
	TEACHER(3, "teacher"),
	STUDENT(4, "student");

	private int  index;
	private String  name;
	
    private RoleType(int index, String name) {
    	this.index = index;
    	this.name = name;
    }
    
    public static RoleType getByName(String role){
    	if(StringUtils.isEmpty(role)){
    		return RoleType.USER;
    	}else if(role.equalsIgnoreCase("admin")){
    		return RoleType.ADMIN;
    	}else if(role.equalsIgnoreCase("teacher")){
    		return RoleType.TEACHER;
    	}else if(role.equalsIgnoreCase("student")){
    		return RoleType.STUDENT;
    	}else{
    		return RoleType.USER;
    	}
    }

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String toString() {
		return this.name;
	}
}
